<?php
include_once 'basepath.php';
print_r($idbus."--idtour".$idtour);
/*test*/

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

<link rel="stylesheet" href="<?php echo $bpath;?>/css/reset.css" />
<link rel="stylesheet" href="<?php echo $bpath;?>/css/text.css" />
<link rel="stylesheet" href="<?php echo $bpath;?>/css/960_24_col.css" />
 <link rel="stylesheet" href="<?php echo $bpath;?>/css/jquery-ui-1.8.21.custom.css" />
  <link rel="stylesheet" href="<?php echo $bpath;?>/css/faary.css" type="text/css" />
 <link rel="stylesheet" href="<?php echo $bpath;?>/css/style.css" />
 <link rel="stylesheet" href="<?php echo $bpath;?>/css/apprise.min.css" type="text/css">

 <script type="text/javascript" src="<?php echo $bpath;?>/js/jquery-1.7.2.min.js"></script>
 <script type="text/javascript" src="<?php echo $bpath;?>/js/jquery-ui-1.8.21.custom.min.js"></script>
<script type="text/javascript" src="<?php echo $bpath;?>/js/scripts.js"></script>
 <script type="text/javascript" src="<?php echo $bpath;?>/js/jquery.validate.js"></script>
 	<script type="text/javascript" src="<?php echo $bpath;?>/js/apprise-1.5.min.js"></script>"
 <script type="text/javascript">
	$(function(){
		//CHANGE PRICE BY NB PEOPELE
	$("#numberpeople").change(function(){
				var nb=$(this).val();
				var unitprix=$("#unitprice").val();
				var total=nb*unitprix;
				$("#SalsePrice").val(total.toFixed(2));

			})
		
		//acount le chambre and person equibre
		function ckchambrepeople()
					{
						var singletotal=$("input#c1").val();
						var doubletotal=$("input#c2").val()*2;
						var tripletotal=$("input#c3").val()*3;
						var quadruple=$("input#c4").val()*4;
						var totalpeople=$("select#numberpeople").val();
						var ecart=parseInt(totalpeople)-(parseInt(singletotal)+parseInt(doubletotal)+parseInt(tripletotal)+parseInt(quadruple));
						//alert(totalpeople);
						return ecart;
					}


		jQuery.validator.addMethod("telphone", function(value, element) { 
			  return this.optional(element) || /^\d{3}\-\d{7}$/.test(value); 
			}, "Please specify the correct domain");
		
		$(".forminscr").validate({
				submitHandler: function(form){ 
					telnumber=$("input.nbtel").val();
					getidclient=$("input.get_idclient").val();
					if(getidclient==0){
					 $.ajax({
				            url: "index.php?add/seachclientbytel/"+telnumber,
				            type:'POST',
				            dataType: 'json',
				            success: function(output_string){
					            if(output_string.etat=="yes"){
									var str_info="This telephone number exit , click check for get more information"

				                 	apprise(str_info, {'verify':false}, function(r)
											 {
				                 			

											 });//alert yes

					           	 		}else{
					           	 		
					           	 		//form.submit() ;
				           	 				var ecartchambre=ckchambrepeople()
											if(ecartchambre>=0)
										{ 
												var placeask=$("#numberpeople").val();
												var idbus=$("input[name=idbus]").val();
												if(chkplace(idbus,placeask)=="yes")	
												{
													form.submit() 
												}else(alert("This bus has not Enough seat for booking"));	
										}else{

											alert("You choice bad nomber chamber")
										}
						           	 		
					           	 	}//etat is yess or ono
				                } // End of success function of ajax form
				            }); // End of ajax call 
					}else{
				            var ecartchambre=ckchambrepeople()
							if(ecartchambre>=0)
						{ 
								var placeask=$("#numberpeople").val();
								var idbus=$("input[name=idbus]").val();
								if(chkplace(idbus,placeask)=="yes")	
								{
									form.submit() 
								}else(alert("This bus has not Enough seat for booking"));	
						}else{

							alert("You choice bad nomber chamber")
						}
					}
					},
				 onfocusout:  function(element) { $(element).valid(); },

				rules: {
					
					FirstName: {
						required: true,
						minlength: 3
					},
				
					
					LastName: {
						required: true,
						minlength: 3
		     		 },
		   			
		     		Telephone: {
		     		 required: true,
		     		 telphone:true
		     		 			},
		     		 Email : {
		     		 required: true,
		     		email:true
		   			},

		     		Language: {
		     			 required: true
		     				},  			
		     		SalsePrice:{
		     			required: true
			     		}
				},
				
				messages: {
					FirstName: "Enter First Name(at least 3 caracter )",
					LastName: "Enter First Name(at least 3 caracter )",
					Telephone:"Enter Number telephone(format:xxx-xxxxxxx)",
					Email:"Enter Email"
					}
				
		});

//check client exit in table clients?
		$("input.tel").click(function(){
			telnumber=$("input.nbtel").val();
			$("input.nbtel").removeAttr("disabled");
			
		 $.ajax({
	            url: "index.php?add/seachclientbytel/"+telnumber,
	            type:'POST',
	            dataType: 'json',
	            success: function(output_string){
		            if(output_string.etat=="yes"){
						var str_info="<h3 align='center'>Client's Information found</h3><table width='500' border='1'><tr><td>Fisrt Name:</td><td>"+output_string[0].firstname+"</td><td>Last Name:</td><td>"+output_string[0].lastname+"</td></tr>	<tr><td>Tel:</td><td>"+output_string[0].telphone+"</td><td>Email:</td><td>"+output_string[0].email+"</td>	</tr></table><h4 align='center'>you want use this infomation?</h4>"

	                 	apprise(str_info, {'verify':true}, function(r)
								 {
									 if(r){
											$("input.get_idclient").val(output_string[0].idclients);
											$("input#FirstName").val(output_string[0].firstname);
											$("input#LastName").val(output_string[0].lastname);
											$("input#Email").val(output_string[0].email);
											$("input#address").val(output_string[0].address);
											//alert("yes")
											$("input.nbtel").attr("readonly","");
										 }else{

											 $("input.nbtel").val("");
											 $("input.get_idclient").val(0);
											 $("input#FirstName").val("");
											 $("input#LastName").val("");
											 $("input#Email").val("");
											 $("input#address").val("");
											 $("input.nbtel").removeAttr("readonly")

											 }

								 });//alert yes

		           	 		}else
			           	 		{
									alert("This Telephone Number isn't found !");
			           	 		}//etat is yess or no
	                } // End of success function of ajax form
	            }); // End of ajax call 
	 			
			});//click 





//############ change le chambre###########################
		$("#slider1").slider({
			range: false,
			min: 0,
			max: 10,
			step:1,
			values: [1],
			slide: function(event, ui) {
				
				$("#start1").text(ui.values[0]);
				$("input#c1").val(ui.values[0]);
			
				
			}
		});
		$("#slider2").slider({
			range: false,
			min: 0,
			max: 10,
			step:1,
			values: [1],
			slide: function(event, ui) {
				
				$("#start2").text(ui.values[0]);
				$("input#c2").val(ui.values[0]);
				
			}
		});	
		
		$("#slider3").slider({
			range: false,
			min: 0,
			max: 10,
			step:1,
			values: [1],
			slide: function(event, ui) {
				
				$("#start3").text(ui.values[0]);
				$("input#c3").val(ui.values[0]);
				
				}
		});	
		$("#slider4").slider({
			range: false,
			min: 0,
			max: 10,
			step:1,
			values: [1],
			slide: function(event, ui) {
				
				$("#start4").text(ui.values[0]);
				$("input#c4").val(ui.values[0]);
				
				}
		});	


		function chkplace(idbus,placeask)
		{
			var returnvalue="no";
			$.ajax({
            url: "index.php?liste/ckplacevalid/"+idbus,
            type:'POST',
            dataType: 'json',
            async:false,
            success: function(output_string){
				
            	var validplace=output_string;
            	var ecart=validplace-placeask;
            	if(ecart>=0)
            	{returnvalue="yes"}else{returnvalue="no"};
				
            	}
				});//ajax
			return returnvalue;
		}

		
		})
</script>
</head>

<body>
	
	<div class="principal container_24">
		
		<!--logo-->
		<div class="logo grid_24">
			<div class="grid_1">&nbsp;</div>
			<div class="grid_4 logoimage"><img src="<?php echo $bpath;?>/img/logo.png" height="90"></div>
			<div class="logout grid_5"><a href=""><img src="<?php echo $bpath;?>/img/bt_logout.jpg"/></a></div>
		</div><!-- end logo-->
		
		<!--menupricipal-->
		<div class="menuprincipal grid_24">
			<a class="yearlist " href="index.php?liste/listtour">Back to List </a>
		</div>
		<!-- end menupricipal-->
				
			<div class="descprincipal grid_22">
				description
			</div>
			
			<div class="grid_24 listcontent">
				<h1>CLIENT INSCRIPTION</h1>
				<div class="grid_22 list">
<form method="post" action="index.php?add/actionAdd/bookinggroup" class="iform grid_18 forminscr" onSubmit="return false" >
<input type="hidden" name="unitprice" id="unitprice" value="<?php echo $fixedprice;?>">
<input type="hidden" name="idclient" class="get_idclient" value=0>
<input type="hidden" name="idbus" value="<?php echo $idbus;?>">
<input type="hidden" id="c1" name="c1" value="0">
<input type="hidden" id="c2" name="c2" value="0">
<input type="hidden" id="c3" name="c3" value="0">
<input type="hidden" id="c4"name="c4" value="0">
<input type="hidden" name="addbookingID" value="<?php echo $addbookingID;?>">
<div id="imessageOK">Thank you! Message Sent!</div>
<div id="imessageERROR">ERROR: Message Not Sent!</div>
<ul>

<li class="iheader">CLIENT INSCRIPTION</li>
<li><label for="Telephone">*Telephone</label><input class="itext nbtel" type="text" name="Telephone" id="Telephone" /><input type="button" class="tel" value="check"></li>
<li><label for="FirstName">*First Name</label><input class="itext" type="text" name="FirstName" id="FirstName" /></li>
<li><label for="LastName">*Last Name</label><input class="itext" type="text" name="LastName" id="LastName" /></li>
<li><label for="Email">*Email</label><input class="itext" type="text" name="Email" id="Email" /></li>
<li><label for="address">Address</label><input class="itext" type="text" name="address" id="address" /></li>
<li><label for="numberpeople">*number people</label><select class="iselect" name="numberpeople" id="numberpeople"><option value="1" selected>1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
</select></li>
<li><label for="Language">*Language</label><ul class="langlist"><li><input class="icheckbox" type="checkbox" name="Language" id="Language2" value="French"><label for="Language2" class="ilabel">French</label></li>
<li><input class="icheckbox" type="checkbox" name="Language" id="Language3" value="English"><label for="Language3" class="ilabel">English</label></li>
<li><input class="icheckbox" type="checkbox" name="Language" id="Language4" value="Spain"><label for="Language4" class="ilabel">Spain</label></li>
<li><input class="icheckbox" type="checkbox" name="Language" id="Language5" value="Chinese"><label for="Language5" class="ilabel">Chinese</label></li>
<li><input class="icheckbox" type="checkbox" name="Language" id="Language6" value="Japanese"><label for="Language6" class="ilabel">Japanese</label></li>
<li><input class="icheckbox" type="checkbox" name="Language" id="Language7" value="Korean"><label for="Language7" class="ilabel">Korean</label></li>
</ul></li>
<li><label for="Description">*Description</label><textarea class="itextarea" name="Description" id="Description" readonly><?php echo $desc;?></textarea></li>
<li><label for="SalsePrice">*Salse Price</label>$<input class="itext" type="text" name="SalsePrice" value="<?php echo $fixedprice;?>" id="SalsePrice" /></li>
<li><label for="Chambre">Chambre</label><ul class="chambrelist group">
<li><label for="Chambre2" class="ilabel">Single</label>&nbsp;<span id="start1">0</span>&nbsp; <div id="slider1"></div></li>
<li><label for="Chambre3" class="ilabel">Double</label>&nbsp;<span id="start2">0</span>&nbsp; <div id="slider2"></div></li></li>
<li><label for="Chambre4" class="ilabel">Triple</label>&nbsp;<span id="start3">0</span>&nbsp; <div id="slider3"></div></li></li>
<li><label for="Chambre5" class="ilabel">Quadruple</label>&nbsp;<span id="start4">0</span>&nbsp; <div id="slider4"></div></li></li>
</ul></li>
<li><label for="Reminder">*Reminder</label><textarea class="itextarea" name="Reminder" id="Reminder"></textarea></li>
<li><label for="Paid">Paid</label><ul><li>NO<input class="iradio" type="radio" name="Paid" id="Paid2" value="0" checked="checked">&nbsp;&nbsp;YES<input class="iradio" type="radio" name="Paid" id="Paid2" value="1"><label for="Paid2" class="ilabel"></label></li>
</ul></li>
<li><label>&nbsp;</label><input type="submit" class="ibutton sbforminscr"  name="SendaMessage" id="SendaMessage" value="Submit" /></li>
</ul></form>
				</div>
			</div>
		
	</div><!--end principal-->
</body>
</html>